/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package uk.ac.cam.can;

import uk.ac.cam.can.generalisator.GenZip;
import uk.ac.cam.can.generalisator.GenAgeRange;
import uk.ac.cam.can.generalisator.GenCountry;
import uk.ac.cam.can.generalisator.GenDrug;
import uk.ac.cam.can.generalisator.GenMarStatus;
import uk.ac.cam.can.generalisator.Generalisator;
import uk.ac.cam.can.generalisator.GenSuppression;
import uk.ac.cam.can.generalisator.GenEducation;
import uk.ac.cam.can.generalisator.GenDate;
import uk.ac.cam.can.generalisator.GenBirthDate;
import uk.ac.cam.can.generalisator.GenNull;
import uk.ac.cam.can.generalisator.GenWorkingClass;
import uk.ac.cam.can.algorithm.KAnon;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import uk.ac.cam.can.algorithm.CutingKAnon;
import uk.ac.cam.can.algorithm.CutingLDiverse;
import uk.ac.cam.can.algorithm.LDiverse;
import uk.ac.cam.can.watermarking.Watermark;
/**
 *
 * @author Thomas
 */
public class Anon {
    /**
     * @param args the command line arguments
     */
    static Map results = new HashMap();
    static Map attributes = new HashMap();
    
    
    
    public static void main(String[] args) throws Exception{
        for(int i = 0; i < 10; i++){
            System.out.println("K="+i);
            System.out.println("K-Anon");
            KAnon k = new KAnon(getAdult(), 8, 0.01*(double)i);
            k.findBest();            
            k.printResult();
            k.saveBest("./tmp/"+i+"-k-anon.csv");
            System.out.println();
            
            System.out.println("CutingKAnon");
            CutingKAnon a = new CutingKAnon(getAdult(), 8, 16, 0.01*(double)i);
            a.findBest();
            a.printResult();
            System.out.println();
        }
    }
    
    public static Data getPatients(String fileName, int[] pcost){
        int[] type = new int[6];
        type[0]=Data.TYPE_PSEUDO_IDENTIFIER;
        type[1]=Data.TYPE_QUASI_IDENTIFIER;
        type[2]=Data.TYPE_QUASI_IDENTIFIER;
        type[3]=Data.TYPE_QUASI_IDENTIFIER;
        type[4]=Data.TYPE_NON_SENSITIVE;
        type[5]=Data.TYPE_SENSITIVE;
        
        Generalisator[] gen = new Generalisator[6];
        gen[0]=new GenNull();
        gen[1]=new GenBirthDate();
        gen[2]=new GenZip();
        gen[3]=new GenSuppression();
        gen[4]=new GenSuppression();
        gen[5]=new GenSuppression();
        
        return new Data(fileName, ";", type, gen, pcost);
    }
    
    public static Data getEvents(int ecost[]){
        int[] type = new int[3];
        type[0]=Data.TYPE_PSEUDO_IDENTIFIER;
        type[1]=Data.TYPE_QUASI_IDENTIFIER;
        type[2]=Data.TYPE_QUASI_IDENTIFIER;
        
        Generalisator[] gen = new Generalisator[3];
        gen[0]=new GenNull();
        gen[1]=new GenDate();
        gen[2]=new GenDrug();

        return new Data("./chemio.csv", ";", type, gen, ecost);
    }
    
    public static Data getAdult(){
        int[] type = new int[9];
        type[0]=Data.TYPE_QUASI_IDENTIFIER;
        type[1]=Data.TYPE_QUASI_IDENTIFIER;
        type[2]=Data.TYPE_QUASI_IDENTIFIER;
        type[3]=Data.TYPE_QUASI_IDENTIFIER;
        type[4]=Data.TYPE_QUASI_IDENTIFIER;
        type[5]=Data.TYPE_QUASI_IDENTIFIER;
        type[6]=Data.TYPE_SENSITIVE;
        type[7]=Data.TYPE_SENSITIVE;
        type[8]=Data.TYPE_SENSITIVE;
        
        Generalisator[] gen = new Generalisator[9];
        gen[0]=new GenAgeRange(); // age
        gen[1]=new GenSuppression(); // gender
        gen[2]=new GenSuppression(); // race
        gen[3]=new GenMarStatus(); // mar statut
        gen[4]= new GenEducation();
        gen[5]= new GenCountry();
        gen[6]=new GenWorkingClass();
        gen[7]=new GenSuppression(); //salary
        gen[8]=new GenSuppression(); //occupation
        
        //int[] cost = {1, 1600, 4800, 25, 5, 400, 100, 14400, 28800};
        //int[] cost = {2880, 16, 48, 144, 576, 11520, 4, 1, 2};
        int[] cost = { 6, 9, 8, 7, 5, 4, 3, 2, 1};
        return new Data("./adult.txt", ",", type, gen, cost);
    }
    
    public static Data getAdultWithId(String fileName){
        int[] type = new int[10];
        type[0]=Data.TYPE_PSEUDO_IDENTIFIER;
        type[1]=Data.TYPE_QUASI_IDENTIFIER;
        type[2]=Data.TYPE_QUASI_IDENTIFIER;
        type[3]=Data.TYPE_QUASI_IDENTIFIER;
        type[4]=Data.TYPE_QUASI_IDENTIFIER;
        type[5]=Data.TYPE_QUASI_IDENTIFIER;
        type[6]=Data.TYPE_QUASI_IDENTIFIER;
        type[7]=Data.TYPE_SENSITIVE;
        type[8]=Data.TYPE_SENSITIVE;
        type[9]=Data.TYPE_SENSITIVE;
        
        Generalisator[] gen = new Generalisator[10];
        gen[0]=new GenNull(); // age
        gen[1]=new GenAgeRange(); // age
        gen[2]=new GenSuppression(); // gender
        gen[3]=new GenSuppression(); // race
        gen[4]=new GenMarStatus(); // mar statut
        gen[5]= new GenEducation();
        gen[6]= new GenCountry();
        gen[7]=new GenWorkingClass();
        gen[8]=new GenSuppression(); //salary
        gen[9]=new GenSuppression(); //occupation
        
        //int[] cost = {1, 1600, 4800, 25, 5, 400, 100, 14400, 28800};
        //int[] cost = {2880, 16, 48, 144, 576, 11520, 4, 1, 2};
        int[] cost = { 10, 6, 9, 8, 7, 5, 4, 3, 2, 1};
        return new Data(fileName, ",", type, gen, cost);
    }
}
